package com.aos.erp.message.rpc;

import com.alibaba.fastjson.JSON;
import com.aos.erp.common.bean.ResultEntity;
import com.aos.erp.message.model.vo.PushMessageVo;
import com.aos.erp.message.model.vo.SmsMessageVo;
import com.aos.erp.message.service.MessageRecordService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@Api(tags = {"服务接口：发送消息"})
@RestController
@RequestMapping("/service/message")
public class RpcMessageController {

    @Resource
    MessageRecordService messageRecordService;

    @ApiOperation(value = "推送模板消息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mtId", value = "消息模板ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "studentList", value = "推送学员列表[{studentId:学员id,idNo:'证件号码',studentName:'学员名字',studentPhone:'学员电话',pushMessageForApp:'APP推送消息内容',msgParamsForApp:'APP消息参数([{paramKey:\'{studentName}\', paramValue:\'张军\'}])',pushMessageForPublic:'微信公众号推送消息内容',msgParamsForPublic:'微信公众号消息参数([{paramKey:\'{studentName}\', paramValue:\'张军\'}])',pushMessageForApplet:'微信小程序推送消息内容',msgParamsForApplet:'微信小程序消息参数([{paramKey:\'"+"{studentName}\', paramValue:\'张军\'}])',pushMessageForSms:'短信推送消息内容',msgParamsForSms:'短信消息参数([{paramKey:\'"+"{studentName}\', paramValue:\'张军\'}])'}]", required = true, dataType = "List"),
            @ApiImplicitParam(name = "dsId", value = "发送驾校ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "dsName", value = "发送驾校名称", required = true, dataType = "String"),
            @ApiImplicitParam(name = "senderName", value = "操作人", required = true, dataType = "String"),
            @ApiImplicitParam(name = "bizData", value = "根据APP业务需要，推送消息时提供给APP使用的数据；数据为JSON格式的字符串", required = true, dataType = "String"),
            @ApiImplicitParam(name = "formId", value = "表单提交场景下，为 submit 事件带上的 formId；支付场景下，为本次支付的 prepay_id", required = true, dataType = "String")
    })
    @PostMapping("/pushMessage")
    public ResultEntity pushMessage(@ApiParam("入参") @RequestBody PushMessageVo params) throws Exception{

        messageRecordService.saveRecord(params);
        return ResultEntity.success("推送成功");
    }

    @ApiOperation(value = "发送短信")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "phone", value = "接收人手机号", required = true, dataType = "String"),
            @ApiImplicitParam(name = "smsType", value = "短信类型：sms_yzm为发验证码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "msgParams", value = "消息参数(验证码：[{paramKey:'code',paramValue:'11111'}])", dataType = "String")
    })
    @PostMapping("/sendSmsMessage")
    public ResultEntity sendSmsMessage(@ApiParam("入参") @RequestBody SmsMessageVo params) throws Exception{

        log.info(JSON.toJSONString(params));
//        PushMessageVo messageRecordVo = new PushMessageVo();
//        messageRecordVo.setStudentPhone(params.getPhone());
//        messageRecordVo.setSmsType(params.getSmsType());
//        messageRecordVo.setMsgParamsForSms(params.getMsgParams());
        messageRecordService.saveSmsRecord(params);
        return ResultEntity.success("发送成功");
    }
}
